import { Entity, Column, Index, ManyToOne, JoinColumn, PrimaryColumn } from 'typeorm';
import { Wristband } from './wristband.entity';

@Entity('wristband_adv_last')
@Index('idx_gw_mac_time', ['gw_mac', 'time']) // 复合索引 (gw_mac, time)
// @Index('idx_mac_time', ['mac', 'time']) // 复合索引 (mac, time)
// @Index('idx_time', ['time']) // 单字段索引 (time)
export class WristbandAdvLast {
  @Column({ type: 'char', length: 17, nullable: true })
  @Index()
  gw_mac: string;

  @PrimaryColumn({ type: 'char', length: 17 })
  @Index()
  mac: string;

  @Column({ type: 'tinyint', unsigned: true, nullable: true })
  idx: number;

  @Column({ type: 'int', nullable: true })
  rssi: number;

  @Column({ type: 'smallint', unsigned: true, nullable: true })
  beacon1: number;

  @Column({ type: 'smallint', unsigned: true, nullable: true })
  beacon2: number;

  @Column({ type: 'smallint', unsigned: true, nullable: true })
  beacon3: number;

  @Column({ type: 'int', nullable: true })
  acc_x: number;

  @Column({ type: 'int', nullable: true })
  acc_y: number;

  @Column({ type: 'int', nullable: true })
  acc_z: number;

  @Column({ type: 'int', unsigned: true, nullable: true })
  steps: number;

  @Column({ type: 'tinyint', unsigned: true, nullable: true })
  hr: number;

  @Column({ type: 'int', nullable: true })
  hrv: number;

  @Column({ type: 'tinyint', unsigned: true, nullable: true })
  hr_confidence: number;

  @Column({ type: 'float', nullable: true })
  temperature: number;

  @Column({ type: 'tinyint', unsigned: true, nullable: true })
  bat_vol: number;

  @Column({ type: 'tinyint', nullable: true })
  charging: number;

  @Column({ type: 'tinyint', nullable: true })
  wear_on: number;

  @Column({ type: 'tinyint', nullable: true })
  req_rt: number;

  @Column({ type: 'tinyint', nullable: true })
  fake_hr: number;

  @Column({ type: 'tinyint', nullable: false })
  format: number;

  @Column({ type: 'datetime', nullable: true })
  time: Date;

  @Column({ type: 'float', nullable: true })
  motion: number;

  @Column({ type: 'float', nullable: true })
  motion_variance: number;

  @Column({ type: 'tinyint', nullable: true })
  connected: number;

  // Define the relationship to the Wristband entity
  @ManyToOne(() => Wristband, (wristband) => wristband.wristbandAdv)
  @JoinColumn({ name: 'mac', referencedColumnName: 'mac' }) // Adjust the columns for the relationship
  wristband: Wristband;
}